package com.mes.cloud.controller;

import com.mes.cloud.dto.BmeBcProcessDTO;
import com.mes.cloud.service.BmeBcProcessService;
import com.mes.cloud.utils.JSONResult;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
* 流程配置
* @author wxm
* @Time 2020-4-13
*/
@RestController
@RequestMapping("/bmeBcProcess")
public class BmeBcProcessController {
    private static final Logger LOGGER = LoggerFactory.getLogger(BmeBcProcessController.class);

    @Autowired
    private BmeBcProcessService bmeBcProcessService;

    @RequestMapping(value = "/findList", method = RequestMethod.POST)
    public JSONResult getList(@RequestBody Map<Object, Object> map) {
        JSONResult result = JSONResult.success(bmeBcProcessService.findList(map));
        return result;
    }

    @RequestMapping(value = "/start", method = RequestMethod.POST)
    public JSONResult start(@RequestBody Map<Object, Object> map) {
        bmeBcProcessService.start(map);
        JSONResult result = JSONResult.success();
        return result;
    }

    @RequestMapping(value = "/findPageList", method = RequestMethod.POST)
    public JSONResult getPageList(@RequestBody Map<Object, Object> map) {
        JSONResult result = JSONResult.success(bmeBcProcessService.findPageList(map));
        return result;
    }


    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JSONResult insert(@RequestBody BmeBcProcessDTO bmeBcProcessDTO) {
        JSONResult result = JSONResult.success(bmeBcProcessService.insert(bmeBcProcessDTO));
        return result;
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JSONResult update(@RequestBody BmeBcProcessDTO bmeBcProcessDTO) {
        JSONResult result = JSONResult.success(bmeBcProcessService.update(bmeBcProcessDTO));
        return result;
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public JSONResult delete(@RequestBody BmeBcProcessDTO bmeBcProcessDTO) {
        JSONResult result = JSONResult.success(bmeBcProcessService.delete(bmeBcProcessDTO.getId()));
        return result;
    }

    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public JSONResult get(@RequestBody BmeBcProcessDTO bmeBcProcessDTO) {
        JSONResult result = JSONResult.success(bmeBcProcessService.get(bmeBcProcessDTO.getId()));
        return result;
    }

    @RequestMapping(value = "/getByCode", method = RequestMethod.POST)
    public JSONResult getByCode(@RequestBody BmeBcProcessDTO bmeBcProcessDTO) {
        JSONResult result = JSONResult.success(bmeBcProcessService.getByCode(bmeBcProcessDTO.getCode()));
        return result;
    }

    /**
     * <根据bme_bc_digital基础表标识获取bme_bc_digital基础表>
     *
     * @param map
     * @return long
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "启用禁用")
    @RequestMapping(value = "/enable", method = RequestMethod.POST)
    public JSONResult enable(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcProcessController:Method updateEnable :inParam map: " + map);
        JSONResult jsonResult = null;
        try {
            long count = bmeBcProcessService.enable(map);
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(201, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcProcessController:Method updateEnable :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcProcessController :Method updateEnable :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

}
